"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!
You need to have another while loop, something like this.
You need to have another while loop, something like this, while(true) { Socket sock = servsock.accept(); System.out. Println("Connection from: " + sock.getInetAddress()); Scanner in = new Scanner(sock.getInputStream()); PrintWriter out = new PrintWriter(sock.getOutputStream()); String request = ""; while (in.hasNext()) { request = in.next(); System.out. Println("Request: " + request); if(request.toUpperCase().
Equals("TIME")) { out. Println(getTime()); out.flush(); } else { out. Println("Invalid Request..."); out.flush(); } } }.
Thank you so much! I've been flipping out over this for so long now. I don't know why I didn't see it, but THANK YOU!
– seventeen Nov 30 '09 at 3:45.
From the PrintWriter docs: ...if automatic flushing is enabled it will be done only when one of the println, printf, or format methods is invoked... Your server is calling print() and never flushes the stream, so the time never gets sent. Either call println() or explicitly flush the stream. Also, the server closes the connection immediately after sending the time, so the client's second request always fails... Edit: there's an interesting quirk here - closing the PrintWriter ought to flush it (see the spec of Writer), but due to the order of operations what seems to happen instead is: in.close() closes the underlying Socket out.close() would flush the data written, but can't (as the socket is now closed) Not sure this is exactly what's happening, but swapping the order of these two statements changes the behaviour, presumably giving out.close() a chance to flush...
Thanks, I've changed a few things and I finally got the two to communicate. However, it is still not accepting a second request. I'm updating the code in the question to the current version.
Any ideas? – seventeen Nov 30 '09 at 3:21 After reading the first request, the server just throws away the connection and calls servsock.accept() again, causing it to wait for a new client to connect. – SimonJ Nov 30 '09 at 8:07.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.